﻿using System;

namespace ControleRepresentanteSync.Application
{
    internal abstract class PresenterBase<T> : IDisposable
        where T : IViewModel
    {
        protected T ViewModel { get; private set; }

        protected PresenterBase(T viewModel)
        {
            ViewModel = viewModel;
            ViewModel.OnClose += ViewModelOnClose;
        }

        private void ViewModelOnClose(object sender, EventArgs e)
        {
            Dispose();
        }

        public virtual void Dispose()
        {
            ViewModel.OnClose -= ViewModelOnClose;
        }
    }

    public interface IViewModel
    {
        event EventHandler OnClose;
        void FireOnClose();
    }
}